package com.easy.neo4j.service.impl;

import com.easy.common.util.Result;
import com.easy.neo4j.repository.PowerBikeRepository;
import com.easy.neo4j.service.BikeService;
import com.easy.neo4j.entry.PowerBike;
import com.easy.neo4j.statistics.PowerBikeStatistics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.core.Neo4jClient;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: CoolPro
 * @Description:
 * @Time: 2024-03-29 15:21
 **/
@Component
public class BikeServiceImpl implements BikeService {
    @Resource
    private PowerBikeRepository powerBikeRepository;
    @Autowired
    Neo4jClient neo4jClient;
    @Override
    public Result<String> addBike(String pic,String bikeMode, String platform, String lat, String lng, String bikeId, String cityCode, String mileage, String power, String parkName) {
        powerBikeRepository.addBike(pic,bikeMode, platform, lat, lng, bikeId, cityCode, mileage, power, parkName);
        return Result.success();
    }

    @Override
    public void deleteBike(String bikeNo) {
        powerBikeRepository.deleteBike(bikeNo);
    }

    @Override
    public Result<List<PowerBike>> detailedQueryOfBicycleInformation(String platform, String parkName, String info, String startMileage, String endMileage) {
        return Result.success(powerBikeRepository.detailedQueryOfBicycleInformation(parkName, info, startMileage, endMileage, platform));
    }

    @Override
    public Result getPlatformInfo() {
        Collection<Map<String, Object>>
                all = neo4jClient
                .query("MATCH(p:PowerBike) WITH p.bike_plateform as platform RETURN platform,count(*) as count")
                .fetch()
                .all()
                .stream()
                .filter(platform-> platform.get("platform") != null)
                .collect(Collectors.toList());
        return Result.success(all);
    }


}
